var TableGoodsPendding = function () {
    return {
        init: function () {
		    
            var oTable = $('#table_common').dataTable({
                "aLengthMenu": [
                    [-1,5, 15, 20],
                    ["全部",'5条', '15条', '20条'] 
                ],
                "iDisplayLength": -1,
				"serverSide":true,
				//"aaSorting":[[6,'desc']],
                "sPaginationType": "bootstrap",
				//"bStateSave": true, 
                "oLanguage": {
					"sSearch":"搜索",
                    "sLengthMenu": "每页显示 _MENU_ 记录",    
					"sEmptyTable":"没有数据",
					"sInfo": "当前数据为从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录",   
					"sInfoEmpty": "没有数据",   
					"sInfoFiltered" : "",
					"sInfoPostFix" : "",
					"sLoadingRecords":"",
					"sProcessing": "正在加载数据...", 
					"sZeroRecords": "没有检索到数据", 
                    "oPaginate": {   
						"sFirst": "首页",   
						"sPrevious": "上一页",   
						"sNext": "下一页",   
						"sLast": "尾页"  
					}   
                },
				"sAjaxSource":ajaxUrl,
				"sAjaxDataProp": "data",
				//"sDom":'l<"actions" f>rtip',
				"aoColumns": [
	
					{"sTitle":'序号',"mDataProp": 'goodsId'},
					{"sTitle":'商品图',"mDataProp": 'goodsImg'},
					{"sTitle":'商品名称',"mDataProp": 'goodsName'},
					{"sTitle":'商品编号',"mDataProp": 'goodsSn'},
					{"sTitle":'价格',"mDataProp": 'shopPrice'},
					{"sTitle":'店铺',"mDataProp": 'shopName'},
					{"sTitle":'店铺分类',"mDataProp": 'catName'},
					{"sTitle":'操作',"mDataProp": 'goodsFlag'}
				],
                "aoColumnDefs": [{
                        'bSortable': false,
						'aTargets': ['_all']
                },
				{"aTargets":[0],"sClass":'text-center',"sWidth":'5%'},
				{"aTargets":[1],"mRender":function(data,type,full){	
					data=data?data:goodsImage;
					return '<img src="'+Upload+'/'+data.replace(".","_s.")+'"/>';												
                    },"sClass":'text-center',"sWidth":'5%'},
				{"aTargets":[4],"mRender":function(data,type,full){
					return '<span class="text-danger"><strong>&yen; '+data+'</strong></span>';
				},"sClass":'text-center',"sWidth":'5%'},
				{"aTargets":[7],"mRender":function(data,type,full){
					return '<a class="view btn btn-xs default" href=""><i class="fa fa-eye"></i> 详情</a> <a class="yes btn btn-xs green" href=""><i class="fa fa-check"></i> 通过</a>';
                    },"sClass":'text-center',"sWidth":'5%'}
				],
				"fnCreatedRow":function(nRow,aData,iDataIndex){
					$('td:eq(0)',nRow).html(iDataIndex+1);//为第一个单元格增加序号
				}				
            });

            jQuery('#table_common_wrapper .dataTables_filter input').addClass("form-control input-medium input-inline"); // modify table search input
            jQuery('#table_common_wrapper .dataTables_length select').addClass("form-control input-small"); // modify table per page dropdown
            jQuery('#table_common_wrapper .dataTables_length select').select2({
                showSearchInput : false 
            }); 
			
			var nEditing = null;
				
			//审核通过
            $('#table_common a.yes').live('click', function (e) {
				e.preventDefault();
				var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				layer.confirm('该商品确定通过审核？',function(index){
					$.post(ajaxUrl,{id:aData['goodsId'],ajax:'setStatus',status:1},function(data){
						if(data){
							layer.msg('该商品审核成功！',{icon: 1,time: 2000});
							oTable.fnReloadAjax();
							
						}else{
							layer.msg('该商品审核失败！',{icon: 2,time: 2000});
							return;
						}
				   });					
				});	               
            });
			

			//详情
            $('#table_common a.view').live('click', function (e) {
                e.preventDefault();
                var nRow = $(this).parents('tr')[0];
				var aData = oTable.fnGetData(nRow);
				var url=editUrl+'?goodsId='+aData['goodsId'];
				location.href=url;
            });
        }

    };

}();